package com.cslg.questionnaires.service;

import com.cslg.questionnaires.mapper.QuestionFormMapper;
import com.cslg.questionnaires.utils.QuestionFormUtils;
import com.cslg.questionnaires.utils.QuestionUtils;
import com.cslg.questionnaires.utils.ServiceMessageBuilder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
public class CheckFormDetailsService {
    @Resource
    QuestionFormMapper questionFormMapper;

    public HashMap<String,Object> getFormDetailsByFormId(int formid,int userid,String utype){
        HashMap<String,Object> formMap = (HashMap<String, Object>) questionFormMapper.getFormByFormId(formid, userid, utype);
        if (formMap == null){
            return ServiceMessageBuilder
                    .buildMessage(404,"不存在该表单！",null);
        }else{
            String answerContent_str = (String)formMap.get("answerContent");
            String formContent_str = (String)formMap.get("formContent");
            List<HashMap> answerContent_list = QuestionFormUtils.parseAnswerContent(answerContent_str);
            ArrayList formContent_list = QuestionUtils.parseQuestionContent(formContent_str);
            formMap.put("answerContent",answerContent_list);
            formMap.put("formContent",formContent_list);
            return ServiceMessageBuilder
                    .buildMessage(200,"success",formMap);
        }
    }
}
